﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a list box control.
    /// </summary>
    [Serializable]
    public class Select : Element {
        private bool _autofocus;
        private bool _disabled;
        private Form _form;
        private bool _multiple;
        private int? _selectedIndex;
        private string _name;
        private bool _required;
        private int? _size;

        /// <summary>
        /// Determines whether or not this control has focus when the page is
        /// first loaded.
        /// </summary>
        public bool AutoFocus {
            get { return _autofocus; }
            set { _autofocus = value; }
        }

        /// <summary>
        /// Determines whether or not this control is disabled.
        /// </summary>
        public bool Disabled {
            get { return _disabled; }
            set { _disabled = value; }
        }

        /// <summary>
        /// Determines the parent form of this control.
        /// </summary>
        public Form Form {
            get { return _form; }
            set { _form = value; }
        }

        /// <summary>
        /// Determines whether or not multiple selections are possible.
        /// </summary>
        public bool Multiple {
            get { return _multiple; }
            set { _multiple = value; }
        }

        /// <summary>
        /// Determines the index of the selected &lt;option&gt; element.
        /// </summary>
        public int? SelectedIndex {
            get { return _selectedIndex; }
            set { _selectedIndex = value; }
        }

        /// <summary>
        /// Determines the name of this control.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines whether or not this item is required to be selected for
        /// the parent form to pass validation.
        /// </summary>
        public bool Required {
            get { return _required; }
            set { _required = value; }
        }

        /// <summary>
        /// Determines the number of rows in a list box that should be shown at
        /// one time.
        /// </summary>
        public int? Size {
            get { return _size; }
            set { _size = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _autofocus, "autofocus");
            AttributeWriter.Write(sb, _disabled, "disabled");
            if (_form != null) {
                AttributeWriter.Write(sb, _form.ID, "form");
            }
            AttributeWriter.Write(sb, _multiple, "multiple");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _required, "required");
            AttributeWriter.Write(sb, _selectedIndex, "selectedindex");
            AttributeWriter.Write(sb, _size, "size");
        }
    }
}
